package com.itheima;

import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.TreeSet;

public class LinkedHashSetDemo {
    public static void main(String[] args) {
        LinkedHashSet<String> set = new LinkedHashSet<>();
        set.add("张三");
        set.add("李四");
        set.add("王五");
        set.add("赵六");

        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String s = it.next();
            System.out.println(s);
        }
    }

    public static class TreeSetDemo {
        public static void main(String[] args) {
            test3();
            int a = sum(1,2,3,4,5);
            System.out.println(a);

        }
        public static void test2() {
            //集合只能存储引用数据类型，不能存储基本数据类型
            TreeSet<Integer> set1 = new TreeSet<>();
            //1---》包装成Integer对象---》自动装箱
            set1.add(5);
            set1.add(4);
            set1.add(3);
            set1.add(2);
            set1.add(1);
            for (Integer integer : set1){
                System.out.println(integer);
            }
        }
        public static void test1() {
            TreeSet<Student> set = new TreeSet<>();
            set.add(new Student("王五", 20));
            set.add(new Student("张三", 18));
            set.add(new Student("李四", 19));
            set.add(new Student("赵六", 21));

            for (Student s : set) {
                System.out.println(s.getName() + "---" + s.getAge());
            }
        }
        public static void test3() {
    //        Comparator<Student> comparator = new Comparator<Student>() {
    //            @Override
    //            public int compare(Student o1, Student o2) {
    //                return o1.getAge() - o2.getAge();
    //            }
    //        };

            Comparator<Student> comparator = (o1, o2) -> o1.getAge() - o2.getAge();
                //如果时正序，o1-o2
                //如果时倒序，o2-o1

            TreeSet<Student> set = new TreeSet<>();
            set.add(new Student("王五", 20));
            set.add(new Student("张三", 18));
            set.add(new Student("李四", 19));
            set.add(new Student("赵六", 21));
            for (Student student : set) {
                System.out.println(student.getName() + "---" + student.getAge());
            }
        }
        //可变参数必须时形参的最后一个
        public static int sum(int... a) {
            int total = 0;
            for (int i = 0; i < a.length; i++) {
                total  += a[i];
            }
            return total;
        }


    }
}
